from sqlalchemy import Column, Integer, String, Text, Boolean, ForeignKey,DateTime
from sqlalchemy.orm import relationship
from core.base.orm_model import Base, TimestampMixin
from datetime import datetime


class Department(Base, TimestampMixin):
    __tablename__ = "department"

    id = Column(Integer, primary_key=True, index=True, comment='事业部ID')
    dept_name = Column(String(50), nullable=False, comment='事业部名称')
    dept_code = Column(String(50), unique=True, index=True, comment='事业部编码')
    descriptions = Column(Text, nullable=True, comment='描述信息')
    status = Column(Boolean, nullable=False, default=True, comment='是否启用')
    parent_id = Column(Integer, ForeignKey('department.id'), comment='上级部门ID')
    parent_name = Column(String(50), comment='上级部门名称')
    parent_code = Column(String(50), comment='上级部门编码')
    manager_id = Column(Integer, comment='主管ID')
    manager_name = Column(String(50), comment='主管名称')
    create_time = Column(DateTime, default=datetime.now, comment="创建时间")
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment="更新时间")

    # 关联关系
    #projects = relationship("Project", back_populates="department_info")
    #project_timesheets = relationship("ProjectTimesheet", back_populates="department_info", passive_deletes=True)

    def __repr__(self):
        return f"<Department {self.dept_name}>"